//
//  SKUDetailScrNewV.m
//  ZITHER
//
//  Created by weixin on 2018/9/2.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailScrNewV.h"
//#import "SKUDetailNewVc.h"

@implementation SKUDetailScrNewV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self defaultConfiguration] ;
        [self setUI];
        [self setMasonry];
    }
    return self;
}


-(void)setUI{
    
    [self addSubview:self.DetailWatchScr];
    
    [self addSubview:self.DefultQuestion];

}

-(void)setMasonry{
    
    [self.DetailWatchScr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(self).offset(0);
        make.width.height.mas_equalTo(self);

    }];
    
    [self.DefultQuestion mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(0);
        make.left.mas_equalTo(self.mas_right).offset(kScreenW);
        make.width.height.mas_equalTo(self);
    }];
    
}

-(void)setModel:(skuDetailModel *)model
{
    _model = model;
    self.DetailWatchScr.model = model;
    self.DefultQuestion.model = model;

    if ([model.myEnquiryFlag isEqualToString:@"0"]) {
        self.contentSize = CGSizeMake(kScreenW,0);
    }else if ([model.myEnquiryFlag isEqualToString:@"1"]){//2
        self.contentSize = CGSizeMake(kScreenW*2,0);
    }else{
        self.contentSize = CGSizeMake(kScreenW,0);
    }
    
}

-(SKUDetailWatchScrNewV *)DetailWatchScr{
    if (!_DetailWatchScr) {
        _DetailWatchScr = [[SKUDetailWatchScrNewV alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _DetailWatchScr;
}

- (SKUDefultQuestionNewTB *)DefultQuestion{
    if (!_DefultQuestion) {
        _DefultQuestion = [[SKUDefultQuestionNewTB alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _DefultQuestion;
}

-(void)defaultConfiguration{
    self.bounces = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO; // 默认为YES 取消设置NO
    // 当bounces属性为NO时，以下两个属性设置无效
    self.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
    self.alwaysBounceVertical = YES; // 垂直方向弹簧效果
    self.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
    self.backgroundColor = [UIColor whiteColor];
    self.pagingEnabled = YES;
    self.contentSize = CGSizeMake(kScreenW*2,0);
    self.delegate = self;
    static dispatch_once_t onceToken;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.timeType = YES;
    });
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    if (self.timeType) {
        if (scrollView.contentOffset.x == 0) {
            [self changePage:0];
        }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
            [self changePage:1];
        }
    }
    
}

-(void)changePage:(int)index{
    
//    SKUDetailNewVc *vc = (SKUDetailNewVc*)[self getViewController:[SKUDetailNewVc class]];
//
//    if (index == 0) {
//        
//        [vc.viewBlcak mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(vc.btn1.mas_left).offset(0);
//        }];
//        
//        [vc.viewBlcak setNeedsUpdateConstraints];
//        // 调用此方法告诉self.view检测是否需要更新约束，若需要则更新，下面添加动画效果才起作用
//        [vc.viewBlcak updateConstraintsIfNeeded];
//        
//        [UIView animateWithDuration:0.3 animations:^{
//            [vc.view layoutIfNeeded];
//        }];
//    }else{
//        [vc.viewBlcak mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(vc.btn1.mas_left).offset(kScreenW/2.0);
//        }];
//        
//        [vc.viewBlcak setNeedsUpdateConstraints];
//        // 调用此方法告诉self.view检测是否需要更新约束，若需要则更新，下面添加动画效果才起作用
//        [vc.viewBlcak updateConstraintsIfNeeded];
//        
//        [UIView animateWithDuration:0.3 animations:^{
//            [vc.view layoutIfNeeded];
//        }];
//    }
//  
   
}
@end
